package com.go.where.manager.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.go.where.manager.common.Constants;
import com.go.where.manager.dao.ActivityRetrospectDao;
import com.go.where.manager.page.Pagination;
import com.go.where.manager.pojo.ActivityRetrospectInfo;
import com.go.where.manager.pojo.user.UserInfoVO;
import com.go.where.manager.service.ActivityRetrospectService;

@Service("activityRetrospectService")
public class ActivityRetrospectServiceImpl implements ActivityRetrospectService {

	@Resource(name = "activityRetrospectDao")
	private ActivityRetrospectDao activityRetrospectDao;

	@Override
	public ActivityRetrospectInfo queryByPrimartKey(String cid) {
		return activityRetrospectDao.getByKey(cid);
	}

	@Override
	public Pagination<ActivityRetrospectInfo> queryPage(
			ActivityRetrospectInfo retorspectInfo) {
		Integer count = activityRetrospectDao.totalCount(retorspectInfo);
		retorspectInfo.calculate();
		List<ActivityRetrospectInfo> list = activityRetrospectDao
				.queryList(retorspectInfo);
		Pagination<ActivityRetrospectInfo> page = activityRetrospectDao
				.queryPagination(count, list, retorspectInfo);
		return page;
	}

	@Override
	public int save(ActivityRetrospectInfo retorspectInfo,
			UserInfoVO currentUser) {
		retorspectInfo.setPublishTime(new Date());
		retorspectInfo.setUserId(currentUser.getUserId());
		retorspectInfo.setIsDelete(Constants.NOT_DELETED);
		return activityRetrospectDao.insert(retorspectInfo);
	}

	@Override
	public int update(ActivityRetrospectInfo retorspectInfo,
			UserInfoVO currentUser) {
		retorspectInfo.setUpdateTime(new Date());
		if (currentUser != null) {
			retorspectInfo.setUserId(currentUser.getUserId());
		}
		return activityRetrospectDao.update(retorspectInfo);
	}

	@Override
	public ActivityRetrospectInfo queryByContent(String content) {
		return activityRetrospectDao.queryByContent(content);
	}

}
